var express = require('express')
var path = require('path')
var mongoose = require('mongoose')
var cookieParser = require('cookie-parser')
var session = require('express-session')
var mongoStore = require('connect-mongo')(session)
var port = process.env.PORT || 2018
var app = express()

var dbConn = 'mongodb://localhost/benlai'
mongoose.connect(dbConn)

app.set('views', 'app/views/pages')
app.set('view engine', 'jade')

app.use(cookieParser())
app.use(session({
	resave: false,
	saveUninitialized: true,
	secret: 'b-l-s',
	store: new mongoStore({
		url: dbConn,
		collection: 'blsessions'
	})
}))

if('development' === app.get('env')){
	app.set('showStackError', true)
	app.locals.pretty = true
	mongoose.set('debug', true)
}

require('./config/routes')(app)

app.listen(port)
app.locals.moment = require('moment')
app.use(express.static(path.join(__dirname, 'public')))


console.log('web site started on port: ' + port)
